home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / usr.bin / hostname.c < prev    next >
C/C++ Source or Header  |  1996-11-30  |  456b  |  28 lines

  1. /*
  2.  * Set or display hostname.  Jeff Comstock - Bloomington, MN USA 1992
  3.  * Usage: hostname [name]
  4.  * Only root may change the hostname.
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8.  
  9. main(int argc, char **argv) {
  10. struct utsname uts;
  11.  
  12.     if ( argc == 2 ) {
  13.         if ( sethostname(argv[1],strlen(argv[1]))) {
  14.             perror("sethostname");
  15.             exit(1);
  16.         }
  17.     }
  18.     else {
  19.         if (uname(&uts)) {
  20.             perror("uname");
  21.             exit(1);
  22.         }
  23.         else 
  24.             puts(uts.nodename);
  25.     }
  26.     return(0);
  27. }
  28.